public with sharing class searchpageController {

    //Properties
    public String recId {set;get;}
    public List<Account> accountRecList {get; set;}
    public List<Contact> contactRecList {get; set;}
    public List<Lead> leadRecList {get; set;}
    public List<Opportunity> opportunityRecList {get; set;}
    public boolean accountStatus {get; set;}
    public boolean contactStatus {get; set;}
    public boolean leadStatus {get; set;}
    public boolean opportunityStatus {get; set;}
    public String searchfor { get; set; } 
        
    //Constructor
    Public searchpageController() {
    }
    
    // method for search button
    public PageReference search() {
        accountStatus = false;
        contactStatus = false;
        leadStatus = false;
        opportunityStatus = false;
        
        //Retrieve the search result from Account, Contact, Lead, Oportunity
        String searchquery = 'FIND\''+searchfor+'*\'IN NAME FIELDS RETURNING Account(id,name,phone), Contact(id,name), Lead(id,name),Opportunity(id,name)'; 
        List<List<SObject>>searchList=search.query(searchquery);
        accountRecList = searchList[0];
        contactRecList = searchList[1]; 
        leadRecList = searchList[2];
        opportunityRecList = searchList[3];
        
        if(!accountRecList.isEmpty()) {
                accountStatus = true;
        }
        
        if(!contactRecList.isEmpty()) {
                contactStatus = true;
        }
        
        if(!leadRecList.isEmpty()) {
                leadStatus = true;
        }
        
        if(!opportunityRecList.isEmpty()) {
                opportunityStatus = true;
        }
        
        return null;
    }
    
    public PageReference recinfo() {
        PageReference pgRef = new PageReference('/'+recId );
        return pgRef ;
    }
}